package com.daxue;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import lib.Execute;
import lib.MySQLHelper;

public class Sheng {
	public static void main(String[] args) throws IOException, SQLException {
		Document document = Jsoup.connect("http://gaokao.chsi.com.cn/sch/search--ss-on,option-qg,searchType-1.dhtml").get();
		Elements eles = document.select("[class=search]").select("table").get(0).select("td");
		List<Object[]> names = new ArrayList<Object[]>();
		for (Element ele : eles) {
			System.out.println(ele.text());
			names.add(new Object[] {ele.text()});
		}
		String sql = "insert into Sheng(name) value(?)";
		MySQLHelper.withTransaction(new Execute() {
			@Override
			public void call() throws Exception {
				executeBatch(sql, names);
			}
		});
	}
}
